


import 'dart:convert';

import 'package:bt_tool/basic/bt_controller.dart';
import 'package:bt_tool/basic/bt_utils.dart';
import 'package:bt_tool/widget/bt_text_field.dart';
import 'package:bt_tool/widget/bt_toast.dart';
import 'package:crypto/crypto.dart';
import 'package:get/get.dart';

class EncodeMainController extends BTController{

  final BTTextFieldController inputCtl = BTTextFieldController();
  final BTTextFieldController resultCtl = BTTextFieldController();


  @override
  dispose() {
    inputCtl.dispose();
    resultCtl.dispose();
    super.dispose();
  }



  encodeClick(){
    String inputStr = btCommonSafeStr(inputCtl.textEditingController?.text);
    if(btIsStrEmpty(inputStr)){
      return;
    }

    try {
      resultCtl.textEditingController?.text = Uri.encodeComponent(inputStr);
    } catch (e) {
      BTToast.showToast(e.toString());
    }

  }

  decodeClick(){
    String inputStr = btCommonSafeStr(inputCtl.textEditingController?.text);
    if(btIsStrEmpty(inputStr)){
      return;
    }
    try {
      resultCtl.textEditingController?.text = Uri.decodeComponent(inputStr);
    } catch (e) {
      BTToast.showToast(e.toString());
    }

  }

  exchangeClick(){
    String str1 = btCommonSafeStr(inputCtl.textEditingController?.text);
    String str2 = btCommonSafeStr(resultCtl.textEditingController?.text);
    inputCtl.textEditingController?.text = str2;
    resultCtl.textEditingController?.text = str1;
  }

}